var disableFlag=true;
$(function (){
	var str1='';
	function timeToggle(str){
		str = str.substr(0,4)+'-'+str.substr(4,2)+'-'+str.substr(6,2)+' '+str.substr(8,2)+':'+str.substr(10,2)+':'+str.substr(12,2);
		return str;
	}
	function approvedNoFunc(){
		$(".cameraImgBox").removeClass("cameraImgBoxHis");
		$(".validateBtnBox").removeClass("validateBtnBoxHis");
		$(".cameraImgHeader-close").show();
		$(".cameraImgBtn").show();
		$(".validateBtnBox").show();
		$(".validateBtnBoxHis").hide();
		$(".pageBtnbox").hide();
		
		$(".approvedYes").removeClass("approvedShow");
		$(".approvalPadding2").hide();
		$(".approvalPadding1").show();
		$(".approvalContent .approvedNoTable").html('<tr><th class="orderNum thBgc">序号</th><th class="approvalName thBgc">送物人姓名</th><th class="approvalTime thBgc">时间</th><th class="approvalPhone thBgc">联系电话</th><th class="approvalText thBgc">处理</th></tr>');
	      $.ajax({
			  url: "/provide/info",
			  type: 'get',
			  success:function(data){
				  console.log(data)
			      if(data.status=="200"){
					  infoNum1 = data.data.length;
				      for(var i=0;i<data.data.length;i++){
				    	  var swrxm=data.data[i].swrxm?data.data[i].swrxm:"";
				    	  var swrzjh=data.data[i].swrzjh?data.data[i].swrzjh:"";
				    	  var sjc=data.data[i].sjc?data.data[i].sjc:"";
				    	  var lxdh = data.data[i].lxdh?data.data[i].lxdh:"";
				    	  var uuid = data.data[i].uuid;
				    	  // swrdz = data.data[i].swrdz;
				    	  sjc1 = timeToggle(sjc);
				    	  $(".approvalContent .approvedNoTable").append('<tr uuid='+uuid+'><td class="orderNum orderNumHis">'+(+i+1)+'</td><td class="approvalName">'+swrxm+'('+swrzjh+')</td><td class="approvalTime">'+sjc1+'</td><td class="approvalPhone">'+lxdh+'</td><td class="approvalText"><span class="cd-popup-trigger3 approvalBtn">审批</span></td></tr>');
				      } 
			      }

			  },
			  error:function(error){
			  	$(".validateLogo").html('<img src="/public/img/validate/error.png" style="margin-top:0.30rem;" alt=""/><p>请求错误,请重试!</p>');
				$(".validatePerson").css('backgroundSize','contain');
				$(".validateModalContent .validateLogo").show();
				setTimeout(function (){
			    	$(".validateModalContent .validateLogo").hide();
			    	$("#modal-overlay").hide();
			    	$(".modal-overlay").css("visibility","hidden");
			    },1000);
			  }
			});
	}
	$(".approvedNo").click(function (){
		if(!$(this).hasClass("approvedShow")){
			disableFlag=true;
			$(this).removeClass("approvedHide").addClass("approvedShow");
			approvedNoFunc();
		}

	});
	//总页数
	var pageSum=1;
	$.ajax({
	  url: "/history/pageNumber",
	  type: 'get',
	  async:false,
	  success:function(data){
		  if(data.status==200){
			  pageSum=data.data
		  }
	  }
	});
	var pageNum = 1
	$(".beforePage").click(function (){
		pageNum-=1;
		if(pageNum<=1){
			pageNum=1;
		}
		console.log(pageNum-1)
    	$.ajax({
    		  url: "/history/approve?page="+pageNum,
    		  type: 'get',
    		  success:function(data){
    			  console.log(data);
  	    	  $(".approvalContent .approvedYesTable").html('<tr><th class="orderNum thBgc">序号</th><th class="approvalName thBgc">送物人姓名</th><th class="approvalTime thBgc">时间</th><th class="approvalPhone thBgc">联系电话</th><th class="approvalText thBgc">处理</th></tr>');
    		  
  	    	  for(var i=0;i<data.data.length;i++){
  	    		  var pageNum1 = (+i+1)+(pageNum-1)*8;
  		    	  var swrxm=data.data[i].swrxm?data.data[i].swrxm:"";
  		    	  var swrzjh=data.data[i].swrzjh?data.data[i].swrzjh:"";
  		    	  var sjc=data.data[i].sjc?data.data[i].sjc:"";
  		    	  var lxdh = data.data[i].lxdh?data.data[i].lxdh:"";
  		    	  var uuid = data.data[i].uuid;
  		    	  sjc1 = timeToggle(sjc);
  		    	  // swrdz = data.data[i].swrdz;    
  		    	  $(".approvalContent .approvedYesTable").append('<tr uuid='+uuid+'><td class="orderNum orderNumHis">'+pageNum1+'</td><td class="approvalName">'+swrxm+'('+swrzjh+')</td><td class="approvalTime">'+sjc1+'</td><td class="approvalPhone">'+lxdh+'</td><td class="approvalText"><span class="cd-popup-trigger3 approvalBtnYes">查看</span></td></tr>');
  		      }
    		  },
    		  error:function(error){
    			  console.log(error);
    		  }
    		});
	});
	$(".afterPage").click(function (){
		pageNum+=1;
		if(pageNum>=pageSum){
			pageNum=pageSum;
		}
		console.log(pageNum-1)
    	$.ajax({
    		  url: "/history/approve?page="+pageNum,
    		  type: 'get',
    		  success:function(data){
    			  console.log(data);
  	    	  $(".approvalContent .approvedYesTable").html('<tr><th class="orderNum thBgc">序号</th><th class="approvalName thBgc">送物人姓名</th><th class="approvalTime thBgc">时间</th><th class="approvalPhone thBgc">联系电话</th><th class="approvalText thBgc">处理</th></tr>');
//  	    	$(".orderNumHis").text(i+(pageNum-1)*8+1)
  	    	  for(var i=0;i<data.data.length;i++){
  	    		  var pageNum1 = (+i+1)+(pageNum-1)*8;
  		    	  var swrxm=data.data[i].swrxm?data.data[i].swrxm:"";
  		    	  var swrzjh=data.data[i].swrzjh?data.data[i].swrzjh:"";
  		    	  var sjc=data.data[i].sjc?data.data[i].sjc:"";
  		    	  var lxdh = data.data[i].lxdh?data.data[i].lxdh:"";
  		    	  var uuid = data.data[i].uuid;
  		    	  sjc1 = timeToggle(sjc);
  		    	  // swrdz = data.data[i].swrdz;    
  		    	  $(".approvalContent .approvedYesTable").append('<tr uuid='+uuid+'><td class="orderNum orderNumHis">'+pageNum1+'</td><td class="approvalName">'+swrxm+'('+swrzjh+')</td><td class="approvalTime">'+sjc1+'</td><td class="approvalPhone">'+lxdh+'</td><td class="approvalText"><span class="cd-popup-trigger3 approvalBtnYes">查看</span></td></tr>');
  		      }
    		  },
    		  error:function(error){
    			  console.log(error);
    		  }
    		});
	});
	//-------TODO-----
	$(".validateGoods").on("click",".numGoods",function (){
		if(!disableFlag){
		  	$(".validateLogo").html('<p style="margin-top: 1.1rem;">历史数据仅用于查看,不许修改!</p>');
			$(".validatePerson").css('backgroundSize','contain');
			$(".validateModalContent .validateLogo").show();
	    	$("#modal-overlay").show();
			overlay();
			setTimeout(function (){
		    	$(".validateModalContent .validateLogo").hide();
		    	$("#modal-overlay").hide();
		    	$(".modal-overlay").css("visibility","hidden");
		    },2000);
		}
	});
	$(".validateGoods").on("click",".addGoods",function (){
		if(!disableFlag){
		  	$(".validateLogo").html('<p style="margin-top: 1.1rem;">历史数据仅用于查看,不许修改!</p>');
			$(".validatePerson").css('backgroundSize','contain');
			$(".validateModalContent .validateLogo").show();
	    	$("#modal-overlay").show();
			overlay();
			setTimeout(function (){
		    	$(".validateModalContent .validateLogo").hide();
		    	$("#modal-overlay").hide();
		    	$(".modal-overlay").css("visibility","hidden");
		    },2000);
		}
	});
	$(".validateGoods").on("click",".reduceGoods",function (){
		if(!disableFlag){
		  	$(".validateLogo").html('<p style="margin-top: 1.1rem;">历史数据仅用于查看,不许修改!</p>');
			$(".validatePerson").css('backgroundSize','contain');
			$(".validateModalContent .validateLogo").show();
	    	$("#modal-overlay").show();
			overlay();
			setTimeout(function (){
		    	$(".validateModalContent .validateLogo").hide();
		    	$("#modal-overlay").hide();
		    	$(".modal-overlay").css("visibility","hidden");
		    },2000);
		}
	});
	$(".approvedYes").click(function (){
	  if(!$(this).hasClass("approvedShow")){
		disableFlag=false;
		$(".validateGoods").find(".numGoods").css("backgroundColor","#a5a5a5");
		$(".validateGoods").find(".numGoods").css("color","#fff");
		$(".cameraImgBox").addClass("cameraImgBoxHis");
		$(".validateBtnBox").addClass("validateBtnBoxHis");
		$(".cameraImgHeader-close").hide();
		$(".cameraImgBtn").hide();
		$(".validateBtnBox").hide();
		$(".validateBtnBoxHis").show();
		$(".validateBtnBox").hide();
		$(".pageBtnbox").show();
		$(".reduceGoods").hide();

		
		$(this).removeClass("approvedHide").addClass("approvedShow");
		$(".approvedNo").removeClass("approvedShow");
		$(".approvalPadding2").show();
		$(".approvalPadding1").hide();
    	$.ajax({
  		  url: "/history/approve?page="+pageNum,
  		  type: 'get',
  		  success:function(data){
  			  console.log(data);
	    	  $(".approvalContent .approvedYesTable").html('<tr><th class="orderNum thBgc">序号</th><th class="approvalName thBgc">送物人姓名</th><th class="approvalTime thBgc">时间</th><th class="approvalPhone thBgc">联系电话</th><th class="approvalText thBgc">处理</th></tr>');
  		      
	    	  for(var i=0;i<data.data.length;i++){
  	    		  var pageNum1 = (+i+1)+(pageNum-1)*8;
		    	  var swrxm=data.data[i].swrxm?data.data[i].swrxm:"";
		    	  var swrzjh=data.data[i].swrzjh?data.data[i].swrzjh:"";
		    	  var sjc=data.data[i].sjc?data.data[i].sjc:"";
		    	  var lxdh = data.data[i].lxdh?data.data[i].lxdh:"";
		    	  var uuid = data.data[i].uuid;
		    	  sjc1 = timeToggle(sjc);
		    	  // swrdz = data.data[i].swrdz;    
		    	  $(".approvalContent .approvedYesTable").append('<tr uuid='+uuid+'><td class="orderNum orderNumHis">'+pageNum1+'</td><td class="approvalName">'+swrxm+'('+swrzjh+')</td><td class="approvalTime">'+sjc1+'</td><td class="approvalPhone">'+lxdh+'</td><td class="approvalText"><span class="cd-popup-trigger3 approvalBtnYes">查看</span></td></tr>');
		      }
  		  },
  		  error:function(error){
  			  console.log(error);
  		  }
  		});
		}
	});
	$(".approvalContent").on("click",".approvalBtnYes",function (){
		$(".validateGoods").find(".numGoods").css("backgroundColor","#a5a5a5");
		$(".validateGoods").find(".numGoods").css("color","#fff");
		$(".validateGoods").find(".addGoods").css("backgroundColor","#a5a5a5");
		$(".validateGoods").find(".reduceGoods").css("backgroundColor","#a5a5a5");
    	///provide/getImgNum?uuid=
    	var imguuid = $(this).parent().parent().attr("uuid");
    	var imgUrl1="/provide/getThingImg?uuid="+imguuid+"&xh=1";;
    	var imgUrl2="/provide/getThingImg?uuid="+imguuid+"&xh=2";;
    	var imgUrl3="/provide/getThingImg?uuid="+imguuid+"&xh=3";;
    	var imgUrl4="/provide/getThingImg?uuid="+imguuid+"&xh=4";
    	$.ajax({
  		  url: "provide/getImgNum?uuid="+imguuid,
  		  type: 'get',
  		  success:function(data){
  			  console.log(data);
  			if(data.data==0){
  				$(".cameraImgBox1 .cameraImgText").html('');
  			  }else if(data.data==1){
  				getGoodsImg1();
  			  }else if(data.data==2){
  				getGoodsImg1();
  				getGoodsImg2();
  			  }else if(data.data==3){
				getGoodsImg1();
  				getGoodsImg2();
  				getGoodsImg3();
  			  }else if(data.data==4){
				getGoodsImg1();
  				getGoodsImg2();
  				getGoodsImg3();
  				getGoodsImg4();
  			  }
  		  },
  		  error:function(error){
  			  
  		  }
  		});
    	function getGoodsImg1(){
        	$.ajax({
      		  url: "/provide/getThingImg?uuid="+imguuid+"&xh=1",
      		  type: 'get',
      		  success:function(data){
      		      $(".cameraImgBox1 .cameraImgText").html('<img src="'+imgUrl1+'" />');
      		  },
      		  error:function(error){
      			  $(".cameraImgBox1 .cameraImgText").html('');
      		  }
      		});
    	}
    	function getGoodsImg2(){
        	$.ajax({
      		  url: "/provide/getThingImg?uuid="+imguuid+"&xh=2",
      		  type: 'get',
      		  success:function(data){
      		      $(".cameraImgBox2 .cameraImgText").html('<img src="'+imgUrl2+'" />');
      		  },
      		  error:function(error){
      			  $(".cameraImgBox2 .cameraImgText").html('');
      		  }
      		});
    	}
    	function getGoodsImg3(){
        	$.ajax({
      		  url: "/provide/getThingImg?uuid="+imguuid+"&xh=3",
      		  type: 'get',
      		  success:function(data){
      		      $(".cameraImgBox3 .cameraImgText").html('<img src="'+imgUrl3+'" />');
      		  },
      		  error:function(error){
      			  $(".cameraImgBox3 .cameraImgText").html('');
      		  }
      		});
    	}
    	function getGoodsImg4(){
        	$.ajax({
      		  url: "/provide/getThingImg?uuid="+imguuid+"&xh=4",
      		  type: 'get',
      		  success:function(data){
      		      $(".cameraImgBox4 .cameraImgText").html('<img src="'+imgUrl4+'" />');
      		  },
      		  error:function(error){
      			  $(".cameraImgBox4 .cameraImgText").html('');
      		  }
      		});
    	}
	});
	var uuidValStr;
	$(".approvalPadding2").on("click",".approvalBtnYes",function (){
		uuidValStr = $(this).parent().parent().attr("uuid");
		  $(".listRight li").eq(0).find("img").removeAttr("src");
		  $(".listRight li").eq(1).find("img").removeAttr("src");
		$(".listRight .cameraImgBox").find("img").hide();
		$(".cameraImgBoxStyle").css("background","url(/public/img/photograph.png) no-repeat center 0.53rem");
		$(".cameraImgBoxStyle").css("background-color","#108cbe");
		$(".cameraImgBoxStyle").css("background-size","1rem");
		// $(".listLeft").find(".list5 span").text(swrdz);
		console.log(uuidValStr)
		$(".goodsNumListBox").html("");
		//渲染物品
		$.ajax({
			  url: "/provide/list?uuid="+uuidValStr,
			  type: 'get',
			  async:false,
			  success:function(data){
			      for(var i=0;i<data.data.length;i++){
				      var goodsSl= data.data[i].sl?data.data[i].sl:"0";
				      var goodsWp= data.data[i].wp;
				      var goodsgg = data.data[i].gg;
						$(".cd-popup3").show();
				      $(".goodsNumListBox").append('<div class="goodsNumList"><span class="goodsText">'+goodsWp+'</span><span class="reduceGoods">-</span><span class="numGoods">'+goodsSl+'</span><span class="addGoods">+</span><span class="SpecificationsText">'+goodsgg+'</span></div>');
			    	$(".validateGoods .goodsNumList").eq(i).find(".numGoods").text(goodsSl);
			    	$(".validateGoods .goodsNumList").eq(i).find(".goodsText").text(goodsWp);
			    	//打印
			    	var Specifications=data.data[i].gg?data.data[i].gg:"";
			      }
			  },
			  error:function(error){
			    	$(".validateLogo").html('<img src="/public/img/validate/error.png" style="margin-top:0.30rem;" alt=""/><p>请求错误,请重试!</p>');
			    	$(".validatePerson").css('backgroundSize','contain');
					$(".validateModalContent .validateLogo").show();
			    	setTimeout(function (){
			        	$(".validateModalContent .validateLogo").hide();
			        	$("#modal-overlay").hide();
			        	$(".modal-overlay").css("visibility","hidden");
			        },1000);
			  }
			});
		//送物人信息
		var fxryshzStr;
		
		$.ajax({
			  url: "/provide/backinfo?uuid="+uuidValStr,
			  type: 'get',
			  async:false,
			  success:function(data){
				  console.log(data)
			    swrzjhSub = data.data.swrzjh;
				swrxmSub = data.data.swrxm;
				djbhSub = data.data.djbh;
				nameSub = data.data.name;
				zjhmSub = data.data.zjhm;
				yzyrygxSub = data.data.yzyrygx;
				lxdhSub = data.data.lxdh;
				rsshSub = data.data.rssj;
				sjcSub = data.data.sjc;
				jshSub = data.data.jsh;
			    $(".listLeft tbody tr").eq(0).find(".list1 span").text(data.data.swrxm+'('+data.data.swrzjh+')');
			    $(".listLeft tbody tr").eq(2).find(".list1 span").text(data.data.djbh);
			    $(".listLeft tbody tr").eq(2).find(".list2 span").text(timeToggle(sjcSub));
			    $(".listLeft tbody tr").eq(1).find(".list1 span").text(nameSub+"("+data.data.zjhm+")");
			    $(".listLeft tbody tr").eq(0).find(".list3 span").text(data.data.yzyrygx);
			    $(".listLeft tbody tr").eq(0).find(".list2 span").text(data.data.lxdh);
			    $(".listLeft tbody tr").eq(1).find(".list2 span").text(timeToggle(rsshSub));
			    $(".listLeft tbody tr").eq(2).find(".list3 span").text(username);

			    $("#printing p span").text(djbhSub);
			    $("#printing tr").eq(0).find("td").eq(1).text(nameSub);
			    $("#printing tr").eq(0).find("td").eq(3).text(timeToggle(rsshSub));
			    $("#printing tr").eq(0).find("td").eq(5).text(jshSub);
			    $("#printing tr").eq(1).find("td").eq(1).text(username);
			    $("#printing tr").eq(1).find("td").eq(3).text(timeToggle(sjcSub));
			    $("#printing tr").eq(2).find("td").eq(1).text(swrxmSub);
			    $("#printing tr").eq(2).find("td").eq(5).text(swrzjhSub);

			    $("#printing1 p span").text(djbhSub);
			    $("#printing1 tr").eq(0).find("td").eq(1).text(nameSub);
			    $("#printing1 tr").eq(0).find("td").eq(3).text(timeToggle(rsshSub));
			    $("#printing1 tr").eq(0).find("td").eq(5).text(jshSub);
			    $("#printing1 tr").eq(1).find("td").eq(1).text(username);
			    $("#printing1 tr").eq(1).find("td").eq(3).text(timeToggle(sjcSub));
			    $("#printing1 tr").eq(2).find("td").eq(1).text(swrxmSub);
			    $("#printing1 tr").eq(2).find("td").eq(5).text(swrzjhSub);
			    
					var swrdz = data.data.swrdz;
					$(".listLeft").find(".list5 span").text(swrdz);
			    fxryshzStr = data.data.zjhm;
			  },
			  error:function(error){
			    	$(".validateLogo").html('<img src="/public/img/validate/error.png" style="margin-top:0.30rem;" alt=""/><p>请求错误,请重试!</p>');
			    	$(".validatePerson").css('backgroundSize','contain');
					$(".validateModalContent .validateLogo").show();
			    	setTimeout(function (){
			        	$(".validateModalContent .validateLogo").hide();
			        	$("#modal-overlay").hide();
			        	$(".modal-overlay").css("visibility","hidden");
			        },1000);
			  }
		});
		//在押人员
			$.ajax({
				  url: "/provide/getPrisonerInfo?zjhm="+fxryshzStr,
				  type: 'get',
				  async:false,
				  success:function(data){
					  if(data.status==200){
						    jshSub = data.data.jsh;
						    var rsshSub = data.data.rssh;
						    $(".listLeft tbody tr").eq(1).find(".list3 span").text(data.data.jsh);

					  }else{
			    	        $(".validateLogo").html('<img src="/public/img/validate/error.png" style="margin-top:0.30rem;" alt=""/><p>'+data.message+'</p>');
			    	        $(".validatePerson").css('backgroundSize', 'contain');
			    	        $(".validateModalContent .validateLogo").show();
			    	        setTimeout(function () {
			    	          $(".validateModalContent .validateLogo").hide();
			    	          $("#modal-overlay").hide();
			    	          $(".modal-overlay").css("visibility", "hidden");
			    	        }, 1000);
					  }

				  },
				  error:function(error){
				    	$(".validateLogo").html('<img src="/public/img/validate/error.png" style="margin-top:0.30rem;" alt=""/><p>请求错误,请重试!</p>');
				    	$(".validatePerson").css('backgroundSize','contain');
						$(".validateModalContent .validateLogo").show();
				    	setTimeout(function (){
				        	$(".validateModalContent .validateLogo").hide();
				        	$("#modal-overlay").hide();
				        	$(".modal-overlay").css("visibility","hidden");
				        },1000);
				  }
			});
		
		$.ajax({
			  url: "/ic/getImg?uuid="+uuidValStr,
			  type: 'get',
			  async:false,
			  success:function(data){
				  $(".listRight li").eq(1).find("img").show()
				  $(".listRight li").eq(1).find("img").attr("src","/ic/getImg?uuid="+uuidValStr);
			  },
			  error:function(error){
				  $(".listRight li").eq(1).find("img").hide();
			  }
		});
		//人脸比对结果
		$.ajax({
			  url: "/verify/data?uuid="+uuidValStr,
			  type: 'get',
			  success:function(data){
			      if(data.status==200){
			    	  
				      if(data.data.result=='1'){
				    	  $(".listRight li").eq(0).find('img').show();
				    	  $(".validatePerson").css('background','url(/public/img/validate/identitySuccess-red.png) no-repeat');
				    	  $(".validatePerson").css('backgroundSize','contain');
				    	  $(".listRight li").eq(0).find("img").attr("src","/verify/getImg?uuid="+uuidValStr);
				      }else if(data.data.result=='2'||data.data.result=='3'){
				    	  $(".listRight li").eq(0).find('img').show();
				    	  $(".listRight li").eq(0).find("img").attr("src","/verify/getImg?uuid="+uuidValStr);
				    	  $(".validatePerson").css('background','url(/public/img/validate/identityFail.png) no-repeat');
				    	  $(".validatePerson").css('backgroundSize','contain')
				      }else{
				    	  $(".listRight li").eq(0).find('img').hide();
				    	  $(".validatePerson").css('background','url(/public/img/validate/identityFail.png) no-repeat');
				    	  $(".validatePerson").css('backgroundSize','contain')
				      }
			      }else{
//			    	  $(".listRight li").eq(0).find("span").text("照片")
			    	  $(".listRight li").eq(0).find('img').hide();
			    	  $(".validatePerson").css('background','url(/public/img/validate/identityFail.png) no-repeat');
			    	  $(".validatePerson").css('backgroundSize','contain')
			      }

			      
			  },
			  error:function(error){
		    	  $(".listRight li").eq(0).find('img').hide();
				  console.log(error);
			  }
			});

	});

    $(".validateModalContent .validateListSuPrint").click(function (){
    	$("#modal-overlay").show();
    	overlay();

    	$(".validateLogo").html('<p class="validateLogoP">是否打印?</p><span class="printYes">是</span><span class="submitNo">否</span>');
    	$(".validatePerson").css('backgroundSize','contain');
		$(".validateModalContent .validateLogo").show();
//    	setTimeout(function (){
//    		window.location.reload();
//    	},1000);
    });
    function overlay() {
        var e1 = document.getElementById('modal-overlay');
        e1.style.visibility = "visible";//(e1.style.visibility == "visible") ? "hidden" : 
      }
});